home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Visual Basic new SourceCode and Projects / Adventure game / frmTip.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-05-13  |  5.0 KB  |  155 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTip 
  3.    Caption         =   "Tip of the Day"
  4.    ClientHeight    =   3285
  5.    ClientLeft      =   2370
  6.    ClientTop       =   2400
  7.    ClientWidth     =   5415
  8.    Icon            =   "frmTip.frx":0000
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   3285
  13.    ScaleWidth      =   5415
  14.    ShowInTaskbar   =   0   'False
  15.    WhatsThisButton =   -1  'True
  16.    WhatsThisHelp   =   -1  'True
  17.    Begin VB.CheckBox chkLoadTipsAtStartup 
  18.       Caption         =   "&Show Tips at Startup"
  19.       Height          =   315
  20.       Left            =   120
  21.       TabIndex        =   3
  22.       Top             =   2940
  23.       Width           =   2055
  24.    End
  25.    Begin VB.CommandButton cmdNextTip 
  26.       Caption         =   "&Next Tip"
  27.       Height          =   375
  28.       Left            =   4080
  29.       TabIndex        =   2
  30.       Top             =   600
  31.       Width           =   1215
  32.    End
  33.    Begin VB.PictureBox Picture1 
  34.       BackColor       =   &H00FFFFFF&
  35.       Height          =   2715
  36.       Left            =   120
  37.       Picture         =   "frmTip.frx":0442
  38.       ScaleHeight     =   2655
  39.       ScaleWidth      =   3675
  40.       TabIndex        =   1
  41.       Top             =   120
  42.       Width           =   3735
  43.       Begin VB.Label Label1 
  44.          BackColor       =   &H00FFFFFF&
  45.          Caption         =   "Did you know..."
  46.          Height          =   255
  47.          Left            =   540
  48.          TabIndex        =   5
  49.          Top             =   180
  50.          Width           =   2655
  51.       End
  52.       Begin VB.Label lblTipText 
  53.          BackColor       =   &H00FFFFFF&
  54.          Height          =   1635
  55.          Left            =   180
  56.          TabIndex        =   4
  57.          Top             =   840
  58.          Width           =   3255
  59.       End
  60.    End
  61.    Begin VB.CommandButton cmdOK 
  62.       Cancel          =   -1  'True
  63.       Caption         =   "OK"
  64.       Default         =   -1  'True
  65.       Height          =   375
  66.       Left            =   4080
  67.       TabIndex        =   0
  68.       Top             =   120
  69.       Width           =   1215
  70.    End
  71. Attribute VB_Name = "frmTip"
  72. Attribute VB_GlobalNameSpace = False
  73. Attribute VB_Creatable = False
  74. Attribute VB_PredeclaredId = True
  75. Attribute VB_Exposed = False
  76. Option Explicit
  77. ' The in-memory database of tips.
  78. Dim Tips As New Collection
  79. ' Name of tips file
  80. Const TIP_FILE = "TIPOFDAY.TXT"
  81. ' Index in collection of tip currently being displayed.
  82. Dim CurrentTip As Long
  83. Private Sub DoNextTip()
  84.     ' Select a tip at random.
  85.     CurrentTip = Int((Tips.Count * Rnd) + 1)
  86.     ' Or, you could cycle through the Tips in order
  87. '    CurrentTip = CurrentTip + 1
  88. '    If Tips.Count < CurrentTip Then
  89. '        CurrentTip = 1
  90. '    End If
  91.     ' Show it.
  92.     frmTip.DisplayCurrentTip
  93. End Sub
  94. Function LoadTips(sFile As String) As Boolean
  95.     Dim NextTip As String   ' Each tip read in from file.
  96.     Dim InFile As Integer   ' Descriptor for file.
  97.     ' Obtain the next free file descriptor.
  98.     InFile = FreeFile
  99.     ' Make sure a file is specified.
  100.     If sFile = "" Then
  101.         LoadTips = False
  102.         Exit Function
  103.     End If
  104.     ' Make sure the file exists before trying to open it.
  105.     If Dir(sFile) = "" Then
  106.         LoadTips = False
  107.         Exit Function
  108.     End If
  109.     ' Read the collection from a text file.
  110.     Open sFile For Input As InFile
  111.     While Not EOF(InFile)
  112.         Line Input #InFile, NextTip
  113.         Tips.Add NextTip
  114.     Wend
  115.     Close InFile
  116.     ' Display a tip at random.
  117.     DoNextTip
  118.     LoadTips = True
  119. End Function
  120. Private Sub chkLoadTipsAtStartup_Click()
  121.     ' save whether or not this form should be displayed at startup
  122.     SaveSetting App.EXEName, "Options", "Show Tips at Startup", chkLoadTipsAtStartup.Value
  123. End Sub
  124. Private Sub cmdNextTip_Click()
  125.     DoNextTip
  126. End Sub
  127. Private Sub cmdOK_Click()
  128.     Unload Me
  129. End Sub
  130. Private Sub Form_Load()
  131.     Dim ShowAtStartup As Long
  132.     ' See if we should be shown at startup
  133.     ShowAtStartup = GetSetting(App.EXEName, "Options", "Show Tips at Startup", 1)
  134.     If ShowAtStartup = 0 Then
  135.         Unload Me
  136.         Exit Sub
  137.     End If
  138.         
  139.     ' Set the checkbox, this will force the value to be written back out to the registry
  140.     Me.chkLoadTipsAtStartup.Value = vbChecked
  141.     ' Seed Rnd
  142.     Randomize
  143.     ' Read in the tips file and display a tip at random.
  144.     If LoadTips(App.Path & "\" & TIP_FILE) = False Then
  145.         lblTipText.Caption = "That the " & TIP_FILE & " file was not found? " & vbCrLf & vbCrLf & _
  146.            "Create a text file named " & TIP_FILE & " using NotePad with 1 tip per line. " & _
  147.            "Then place it in the same directory as the application. "
  148.     End If
  149. End Sub
  150. Public Sub DisplayCurrentTip()
  151.     If Tips.Count > 0 Then
  152.         lblTipText.Caption = Tips.Item(CurrentTip)
  153.     End If
  154. End Sub
  155.